<?php 
set_time_limit(0);
ini_set("memory_limit", "12M");
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
//sort LogDate
function CompareLogDateASC($a, $b){
	if ($a[0] == $b[0]) {
		return 0;
	}
	return ($a[0] < $b[0]) ? -1 : 1;
}
function CompareLogDateDESC($a, $b){
	if ($a[0] == $b[0]) {
		return 0;
	}
	return ($a[0] > $b[0]) ? -1 : 1;
}
// sort LogTime
function CompareLogTimeASC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] < $b[1]) ? -1 : 1;
}
function CompareLogTimeDESC($a, $b){
	if ($a[1] == $b[1]) {
		return 0;
	}
	return ($a[1] > $b[1]) ? -1 : 1;
}
// sort User
function CompareUserASC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] < $b[2]) ? -1 : 1;
}
function CompareUserDESC($a, $b){
	if ($a[2] == $b[2]) {
		return 0;
	}
	return ($a[2] > $b[2]) ? -1 : 1;
}
//sort Mode
function CompareModeASC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] < $b[3]) ? -1 : 1;
}
function CompareModeDESC($a, $b){
	if ($a[3] == $b[3]) {
		return 0;
	}
	return ($a[3] > $b[3]) ? -1 : 1;
}

if (isset($_SESSION['s_users']) and is_array($_SESSION['s_users']) and isset($_REQUEST['flag'])) {
	
	$mylist = $_SESSION['s_users'];
    if($_REQUEST['flag']=='10'){
		usort($mylist, 'CompareLogDateASC');
	}elseif($_REQUEST['flag']=='11'){
		usort($mylist, 'CompareLogDateDESC');
	}
	elseif($_REQUEST['flag']=='20'){
		usort($mylist, 'CompareLogTimeASC');
	}elseif($_REQUEST['flag']=='21'){
		usort($mylist, 'CompareLogTimeDESC');
	}
	elseif($_REQUEST['flag']=='30'){
		usort($mylist, 'CompareUserASC');
	}elseif($_REQUEST['flag']=='31'){
		usort($mylist, 'CompareUserDESC');
	}
	elseif($_REQUEST['flag']=='40'){
		usort($mylist, 'CompareModeASC');
	}elseif($_REQUEST['flag']=='41'){
		usort($mylist, 'CompareModeDESC');
	}	
	$_SESSION['s_users'] = $mylist;
	
	$winH = 520;
	if(isset($_REQUEST['winH'])) $winH = $_REQUEST['winH'];
	$pageNum = $_REQUEST['pageNum'];
	$rows_per_page = $_REQUEST['rows_per_page'];
	$pageend = $pageNum*$rows_per_page;
	$pagestart = $pageend - $rows_per_page;
	$index = 0;
	$real =0;
	foreach ($mylist as $key =>$row){
		$index+=1;
		//$mylist[$index] = array($row[logDatetime],$row[UserID],$row[dtStart],$row[dtEnd],$row[carType],$row[carnum],$row[isReg]);				 
		//array_push($mylist, array($row[logDate],$row[logTime],$row[szUser],$row[iMode]));
					 ?>
					 <tr>
					 	<td width="25%"><?=$row[0]?></td>
					 	<td width="25%"><?=$row[1]?></td>
					 	<td width="25%"><?=$row[2]?></td>
					 	<td width="25%"  class="last"><?if ($row[3]==0){echo "로그인";}else if ($row[3]==1){echo "로그아웃";}?></td>
					 </tr> 
	<?php  
		}
			 if ($index>0 and $index<$winH/28) {
			 	foreach(range(0,$winH/28-$index) as $i){
			 		?>
			 		<tr>
				 	<td width="25%">&nbsp;</td>
				 	<td width="25%">&nbsp;</td>
				 	<td width="25%">&nbsp;</td>
				 	<td width="25%"  class="last">&nbsp;</td>
				 	</tr>
			 	<?php }
			 }
		
		
}
?>

